package be.kuleuven.cs.mop.gui.logging;


import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;



/**
 * Utility class for logging purposes
 * @author Ruben Feyen
 */
public abstract class LogUtils {
	
	public static final String format(final Throwable t) {
		if (t == null)
			return "";
		
		final Writer trace = new StringWriter();
		t.printStackTrace(new PrintWriter(trace));
		return trace.toString();
	}
	
	public static final Logger getLogger(final Class<?> c) {
		final Logger logger = Logger.getLogger(c.getName());
		logger.setLevel(Level.CONFIG);
		return logger;
	}
	
	public static final String getLoggerName(final LogRecord record) {
		final String[] path = record.getLoggerName().split("\\.");
		return path[path.length - 1];
	}
	
}